package com.infisight.hudprojector.kdxfspeech;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.Log;

import com.google.gson.Gson;
import com.infisight.hudprojector.R;
import com.infisight.hudprojector.data.VoiceDataClass;
import com.infisight.hudprojector.util.CommonUtil;
import com.infisight.hudprojector.util.Constants;

/**
 * @author hao
 * 
 *         语音控制中心 （语音控制逻辑类与SpeechVoiceRecognition结合使用）
 * 
 */
public class HandleSpeechData {

	public static VoiceDataClass handleDataFunction(Context mContext,
			String text) {
		VoiceDataClass vdc = null;
		// 导航去
		if (text != null
				&& CommonUtil.recognitionKeySplit(text, Constants.F_R_NAV_GOTO) != null) {

			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_NAV_GOTO[0], CommonUtil.recognitionKeySplit(
							text, Constants.F_R_NAV_GOTO),
					Constants.F_C_FOUND_RIGHT_ADDR);
		}
		// 打开导航
		else if (text != null && text.equals(Constants.F_R_OPEN_NAVI[1])) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_OPEN_NAVI[0], Constants.F_R_OPEN_NAVI[1],
					Constants.F_C_INPUT_RIGHT_ADDR);

		}
		// 开始导航
		else if (text != null && text.equals(Constants.F_R_START_NAVI[1])) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_START_NAVI[0], Constants.F_R_START_NAVI[1],
					Constants.F_C_START_NAVI);

		}
		// 返回导航
		else if (text != null && text.contains(Constants.F_R_CONTINUE_NAVI[1])) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_CONTINUE_NAVI[0],
					Constants.F_R_CONTINUE_NAVI[1], Constants.F_C_CONTINUE_NAVI);

		}
		// 结束当前导航
		else if (text != null
				&& text.equals(Constants.F_R_STOP_CURRENT_NAVI[1])) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_STOP_CURRENT_NAVI[0],
					Constants.F_R_STOP_CURRENT_NAVI[1],
					Constants.F_C_STOP_CURRENT_NAVI);

		}
		// 继续当前导航
		else if (text != null
				&& text.equals(Constants.F_R_CONTINUE_CURRENT_NAVI[1])) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_CONTINUE_CURRENT_NAVI[0],
					Constants.F_R_CONTINUE_CURRENT_NAVI[1], "");

		}

		// 总路线
		else if (text != null
				&& text.equals(Constants.F_R_NAVI_ROUTE_PLAN_All_SEE[1])) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_NAVI_ROUTE_PLAN_All_SEE[0],
					Constants.F_R_NAVI_ROUTE_PLAN_All_SEE[1], "");

		}
		// 选择导航路线
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_NAVI_ROUTE_PLAN)) {
			vdc = new VoiceDataClass(Constants.MAIN_NAVI_ACTION,
					Constants.F_R_NAVI_ROUTE_PLAN[0], text, "");

		}
		// 结束导航
		else if (text != null && text.equals(Constants.F_R_STOP_NAVI[1])) {
			Log.i("SpeechVoiceRecognition", "Constants.F_R_STOP_NAVI" + text);

			vdc = new VoiceDataClass(Constants.MAIN_RETURN_HOME_ACTION,
					Constants.F_R_STOP_NAVI[0], Constants.F_R_STOP_NAVI[1],
					Constants.F_C_STOP_NAVI);
		}
		// 首页音乐
		else if (text != null
				&& CommonUtil.recognitionKey(text, Constants.F_R_MUSIC_ON)) {
			Log.i("SpeechVoiceRecognition", "首页音乐:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_ON[0], Constants.F_R_MUSIC_ON[1],
					Constants.F_C_OPEN_MUSIC);

		}// 上一页
		else if (text != null
				&& CommonUtil.recognitionKey(text, Constants.F_R_MUSIC_PAGE_UP)) {
			Log.i("SpeechVoiceRecognition", "上一页:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_PAGE_UP[0],
					Constants.F_R_MUSIC_PAGE_UP[1], "上一页");
		}
		// 下一页
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_MUSIC_PAGE_DOWN)) {
			Log.i("SpeechVoiceRecognition", "下一首:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_PAGE_DOWN[0],
					Constants.F_R_MUSIC_PAGE_DOWN[1], "下一页");
		}
		// 搜索
		else if (text != null && text.contains(Constants.F_R_SEARCH_CONTENT[1])) {
			Log.i("SpeechVoiceRecognition", "搜索:" + text);
			String strs = text.substring(2, text.length());
			vdc = new VoiceDataClass(Constants.COMMON_UTIL_ACTION,
					Constants.F_R_SEARCH_CONTENT[0], strs, strs);
		}
		// 上一首
		else if (text != null
				&& text.contains(Constants.F_R_MUSIC_LAST_MUSIC_PLAY[1])) {
			Log.i("SpeechVoiceRecognition", "上一首:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_LAST_MUSIC_PLAY[0],
					Constants.F_R_MUSIC_LAST_MUSIC_PLAY[1], "上一首");
		}
		// 下一首
		else if (text != null
				&& text.contains(Constants.F_R_MUSIC_NEXT_MUSIC_PLAY[1])) {
			Log.i("SpeechVoiceRecognition", "下一首:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_NEXT_MUSIC_PLAY[0],
					Constants.F_R_MUSIC_NEXT_MUSIC_PLAY[1], "下一首");
		}
		// 暂停播放
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_MUSIC_PAUSE_PLAY)) {
			Log.i("SpeechVoiceRecognition", "暂停播放:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_PAUSE_PLAY[0],
					Constants.F_R_MUSIC_PAUSE_PLAY[1], "暂停播放");
		}
		// 继续播放
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_MUSIC_CONTINUE_PLAY)) {
			Log.i("SpeechVoiceRecognition", "继续播放:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_CONTINUE_PLAY[0],
					Constants.F_R_MUSIC_CONTINUE_PLAY[1], "继续播放");
		}
		// 单曲循环
		else if (text != null
				&& text.contains(Constants.F_R_MUSIC_JUST_ONE_PLAY[1])) {
			Log.i("SpeechVoiceRecognition", "单曲循环:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_JUST_ONE_PLAY[0],
					Constants.F_R_MUSIC_JUST_ONE_PLAY[1], "单曲循环");
		}
		// 顺序播放
		else if (text != null
				&& text.contains(Constants.F_R_MUSIC_ORDER_PLAY[1])) {
			Log.i("SpeechVoiceRecognition", "顺序播放:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_ORDER_PLAY[0],
					Constants.F_R_MUSIC_ORDER_PLAY[1], "顺序播放");
		}
		// 随机播放
		else if (text != null
				&& text.contains(Constants.F_R_MUSIC_RANDOM_PLAY[1])) {
			Log.i("SpeechVoiceRecognition", "随机播放:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_RANDOM_PLAY[0],
					Constants.F_R_MUSIC_RANDOM_PLAY[1], "随机播放");
		}
		// 播放列表
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_MUSIC_ALL_MUSIC_LIST)) {
			Log.i("SpeechVoiceRecognition", "播放列表:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_ALL_MUSIC_LIST[0],
					Constants.F_R_MUSIC_ALL_MUSIC_LIST[1], "随机播放");
		}
		// 退出音乐播放器
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_MUSIC_STOP_PLAY)) {
			Log.i("SpeechVoiceRecognition", "退出音乐播放器:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_MUSIC_ACTION,
					Constants.F_R_MUSIC_STOP_PLAY[0],
					Constants.F_R_MUSIC_STOP_PLAY[1], "退出音乐播放器");
		}
		// 首页OBD
		else if (text != null
				&& text.trim().contains(Constants.F_R_OBD_SHOW[1])) {
			Log.i("SpeechVoiceRecognition", "首页OBD:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_OBD_ACTION,
					Constants.F_R_OBD_SHOW[0], Constants.F_R_OBD_SHOW[1],
					Constants.F_C_OBD_INFO);
		}
		// 首页打电话给某人
		else if (text != null
				&& CommonUtil.recognitionKeySplit(text, Constants.F_R_PHONE_TO) != null) {
			Log.i("SpeechVoiceRecognition", "首页打电话给某人:" + text);
			vdc = new VoiceDataClass(Constants.MAIN_PHONE_ACTION,
					Constants.F_R_PHONE_TO[0], CommonUtil.recognitionKeySplit(
							text, Constants.F_R_PHONE_TO),
					Constants.F_C_PHONE_TO);
		}
		// 上翻联系人
		else if (text != null
				&& CommonUtil.recognitionKey(text, Constants.F_R_PHONE_PAGE_UP)) {
			Log.i("SpeechVoiceRecognition", "上翻:" + text);
			vdc = new VoiceDataClass(Constants.MODEL_PHONE_ACTION,
					Constants.F_R_PHONE_PAGE_UP[0],
					Constants.F_R_PHONE_PAGE_UP[1], "上翻");
		}
		// 下翻联系人
		else if (text != null
				&& CommonUtil.recognitionKey(text,
						Constants.F_R_PHONE_PAGE_DOWN)) {
			Log.i("SpeechVoiceRecognition", "上翻:" + text);
			vdc = new VoiceDataClass(Constants.MODEL_PHONE_ACTION,
					Constants.F_R_PHONE_PAGE_DOWN[0],
					Constants.F_R_PHONE_PAGE_DOWN[1], "下翻");
		}
		// 挂断电话
		else if (text != null && text.equals(Constants.F_R_PHONE_HANG_UP[1])) {
			Log.i("SpeechVoiceRecognition", "挂断：" + text);
			vdc = new VoiceDataClass(Constants.MODEL_PHONE_ACTION,
					Constants.F_R_PHONE_HANG_UP[0],
					Constants.F_R_PHONE_HANG_UP[1], Constants.F_C_PHONE_HANG_UP);
		}
		// 选择第几条item（属于公共action）
		else if (text != null
				&& CommonUtil.recognitionKeySplit(text,
						Constants.F_R_CHOOSE_ITEM) != null) {
			vdc = new VoiceDataClass(Constants.COMMON_UTIL_ACTION,
					Constants.F_R_CHOOSE_ITEM[0], CommonUtil
							.recognitionKeySplit(text,
									Constants.F_R_CHOOSE_ITEM)
							.subSequence(0, 1).toString(),
					Constants.F_C_TASK_IS_OK);

		}
		// 返回首页
		else if (text != null && text.contains(Constants.F_R_RETURN_HOME[1])) {
			Log.i("SpeechVoiceRecognition", "Constants.F_R_RETURN_HOME" + text);
			vdc = new VoiceDataClass(Constants.MAIN_RETURN_HOME_ACTION,
					Constants.F_R_RETURN_HOME[0], Constants.F_R_RETURN_HOME[1],
					Constants.F_C_RETURN_HOME);

		}
		// 退出应用
		else if (text != null && text.contains(Constants.F_R_EXIT_PROJECT[1])) {
			Log.i("SpeechVoiceRecognition", "Constants.F_R_RETURN_HOME" + text);
			vdc = new VoiceDataClass(Constants.MAIN_EXIT_PROJECT_ACTION,
					Constants.F_R_EXIT_PROJECT[0],
					Constants.F_R_EXIT_PROJECT[1], Constants.F_C_RETURN_HOME);

		}
		// 缩放地图
		else if (text != null
				&& (text.contains(Constants.F_R_ENLARGE_OR_NARROW_MAP[1]) || text
						.contains(Constants.F_R_ENLARGE_OR_NARROW_MAP[2]))) {
			Log.i("SpeechVoiceRecognition", "Constants.F_R_ENLARGE_MAP" + text);
			vdc = new VoiceDataClass(Constants.COMMON_UTIL_ACTION,
					Constants.F_R_ENLARGE_OR_NARROW_MAP[0], text, text);

		}
		return vdc;
	}
}
